package com.itany.cloud.config;

import com.itany.cloud.exception.OpenFeignException;
import feign.Logger;
import feign.Response;
import feign.Retryer;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FooConfiguration {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    public Retryer myRetryer(){
        // 参数一:初始间隔时间,单位:毫秒
        // 参数二:重试时最大的间隔时间,单位:描述
        // 参数三:最大请求次数,本身请求的1次+重试了2次
        return new Retryer.Default(100,1,3);
    }

    @Bean
    public ErrorDecoder feignErrorDecoder(){
        System.out.println("*************************正在统一处理异常*************************");
        return new ErrorDecoder() {
            @Override
            public Exception decode(String methodKey, Response response) {
                return new OpenFeignException("调用服务时遇到了异常");
            }
        };
    }
}